import {http} from "@/utils/http/axios";
import {storage} from '@/utils/Storage';

export function saveRole(name) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/role',
    headers: {token: storage.get('token')},
    method: 'POST',
    params: {
      name: name,
    },
  });
}

export function deleteRole(id) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/role?id=' + id,
    headers: {token: storage.get('token')},
    method: 'DELETE',
    params: {
      id: id,
    },
  });
}

export function updateRole(id, name, status, oauths) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/role',
    headers: {token: storage.get('token')},
    method: 'PUT',
    params: {
      id: id,
      name: name,
      status: status,
      oauthIds: oauths,
    },
  });
}

export function rolePage(params) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/role/list',
    headers: {token: storage.get('token')},
    method: 'GET',
    params,
  });
}

// 管理员角色id集合
export function adminRoleIds(id) {
  return http.request({
    url: window.SITE_CONFIG.baseUrl + '/role/admin/ids?id=' + id,
    headers: {token: storage.get('token')},
    method: 'GET',
  });
}
